import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import { usePermissStore } from '../store/permiss';
import Home from '../views/home.vue';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';

const routes: RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/dashboard',
    },
    {
        path: '/',
        name: 'Home',
        component: Home,
        children: [
            {
                path: '/dashboard',
                name: 'dashboard',
                meta: {
                    title: '系统首页',
                    noAuth: true,
                },
                component: () => import(/* webpackChunkName: "dashboard" */ '../views/dashboard.vue'),
            },
            {
                path: '/system-user',
                name: 'system-user',
                meta: {
                    title: '用户管理1',
                    permiss: '11',
                },
                component: () => import(/* webpackChunkName: "system-user" */ '../views/system/user.vue'),
            },
            {
                path: '/system-role',
                name: 'system-role',
                meta: {
                    title: '角色管理',
                    permiss: '12',
                },
                component: () => import(/* webpackChunkName: "system-role" */ '../views/system/role.vue'),
            },
             {
                 path: '/shopManage',
                 meta: {
                 title: '商品管理',
                 permiss: '100',
                 },
                     component: () => import( '@/views/pagesManage/shopManage/goods.vue'),
             },
             {
                 path: '/userManage',
                 meta: {
                 title: '用户管理',
                 permiss: '101',
                 },
                     component: () => import( '@/views/pagesManage/userManage/index.vue'),
             },
             {
                 path: '/orderLog',
                 meta: {
                 title: '订单日志',
                 permiss: '102_1',
                 },
                    component: () => import( '@/views/pagesManage/logManagement/orderLog.vue'),
             },
             {
                 path: '/rechargeLog',
                 meta: {
                 title: '充值日志',
                 permiss: '102_2',
                 },
                     component: () => import( '@/views/pagesManage/logManagement/rechargeLog.vue'),
             },
             //  {
            //      path: '/refundLog',
            //      meta: {
            //      title: '退款日志',
            //      permiss: '102_3',
            //      },
            //          component: () => import( '@/views/pagesManage/logManagement/refundLog.vue'),
            //  },
               {
                 path: '/financialLog',
                 meta: {
                 title: '财务日志',
                 permiss: '102_4',
                 },
                     component: () => import( '@/views/pagesManage/logManagement/financialLog.vue'),
             },
              {
                 path: '/fragmentLog',
                 meta: {
                 title: '实名号订单',
                 permiss: '102_5',
                 },
                    component: () => import( '@/views/pagesManage/logManagement/fragmentLog.vue'),
             },
              {
                 path: '/APILog',
                 meta: {
                 title: 'API账号订单',
                 permiss: '102_6',
                 },
                    component: () => import( '@/views/pagesManage/logManagement/apiGoodList.vue'),
             },
            
              
             
             {
                 path: '/reflectionRecord',
                 meta: {
                 title: '提现记录',
                 permiss: '103',
                 },
                     component: () => import( '@/views/pagesManage/reflectionRecord/index.vue'),
             },
             {
                 path: '/robot',
                 meta: {
                 title: '机器人列表',
                 permiss: '104_1',
                 },
                     component: () => import( '@/views/pagesManage/robot/index.vue'),
             },
             {
                 path: '/automaticReply',
                 meta: {
                 title: '自动回复',
                 permiss: '104_2',
                 },
                     component: () => import( '@/views/pagesManage/robot/automaticReply.vue'),
             },
              {
                 path: '/xGoods',
                 meta: {
                 title: '商品列表',
                 permiss: '105_1',
                 },
                     component: () => import( '@/views/pagesManage/memberStarEnergy/xGoods.vue'),
             },
             {
                 path: '/xGoods1',
                 meta: {
                 title: 'TG星星',
                 permiss: '105_3',
                 },
                     component: () => import( '@/views/pagesManage/memberStarEnergy/xGoods1.vue'),
             },
             {
                 path: '/xGoods2',
                 meta: {
                 title: 'TG能量',
                 permiss: '105_4',
                 },
                     component: () => import( '@/views/pagesManage/memberStarEnergy/xGoods2.vue'),
             },
             {
                 path: '/xGoods3',
                 meta: {
                 title: 'TG老群',
                 permiss: '105_5',
                 },
                     component: () => import( '@/views/pagesManage/memberStarEnergy/xGoods3.vue'),
             },
             {
                 path: '/xGoods4',
                 meta: {
                 title: 'TG智能托管',
                 permiss: '105_6',
                 },
                     component: () => import( '@/views/pagesManage/memberStarEnergy/xGoods4.vue'),
             },
             {
                 path: '/fragmentNumber',
                 meta: {
                 title: 'fragment实名号',
                 permiss: '105_7',
                 },
                     component: () => import( '@/views/pagesManage/memberStarEnergy/fragmentNumber.vue'),
             },
             {
                 path: '/apiGoodList',
                 meta: {
                 title: 'API账号列表',
                 permiss: '105_8',
                 },
                     component: () => import( '@/views/pagesManage/memberStarEnergy/apiGoodList.vue'),
             },
             {
                 path: '/xOrder',
                 meta: {
                 title: '订单列表',
                 permiss: '105_2',
                 },
                     component: () => import( '@/views/pagesManage/memberStarEnergy/xOrder.vue'),
             },
             {
                 path: '/messageList',
                 meta: {
                 title: '消息列表',
                 permiss: '106_1',
                 },
                     component: () => import( '@/views/pagesManage/message/list.vue'),
             },
             {
                 path: '/messageRecord',
                 meta: {
                 title: '推送记录列表',
                 permiss: '106_2',
                 },
                     component: () => import( '@/views/pagesManage/message/record.vue'),
             },

              {
                 path: '/agentManage',
                 meta: {
                 title: '代理管理',
                 permiss: '107',
                 },
                     component: () => import( '@/views/pagesManage/agentManage/index.vue'),
             },
            // {
            //     path: '/system-menu',
            //     name: 'system-menu',
            //     meta: {
            //         title: '菜单管理',
            //         permiss: '13',
            //     },
            //     component: () => import(/* webpackChunkName: "system-menu" */ '../views/system/menu.vue'),
            // },
            // {
            //     path: '/table',
            //     name: 'basetable',
            //     meta: {
            //         title: '基础表格',
            //         permiss: '31',
            //     },
            //     component: () => import(/* webpackChunkName: "table" */ '../views/table/basetable.vue'),
            // },
            // {
            //     path: '/table-editor',
            //     name: 'table-editor',
            //     meta: {
            //         title: '可编辑表格',
            //         permiss: '32',
            //     },
            //     component: () => import(/* webpackChunkName: "table-editor" */ '../views/table/table-editor.vue'),
            // },
            // {
            //     path: '/schart',
            //     name: 'schart',
            //     meta: {
            //         title: 'schart图表',
            //         permiss: '41',
            //     },
            //     component: () => import(/* webpackChunkName: "schart" */ '../views/chart/schart.vue'),
            // },
            // {
            //     path: '/echarts',
            //     name: 'echarts',
            //     meta: {
            //         title: 'echarts图表',
            //         permiss: '42',
            //     },
            //     component: () => import(/* webpackChunkName: "echarts" */ '../views/chart/echarts.vue'),
            // },

            // {
            //     path: '/icon',
            //     name: 'icon',
            //     meta: {
            //         title: '图标',
            //         permiss: '5',
            //     },
            //     component: () => import(/* webpackChunkName: "icon" */ '../views/pages/icon.vue'),
            // },
            // {
            //     path: '/ucenter',
            //     name: 'ucenter',
            //     meta: {
            //         title: '个人中心',
            //     },
            //     component: () => import(/* webpackChunkName: "ucenter" */ '../views/pages/ucenter.vue'),
            // },
            // {
            //     path: '/editor',
            //     name: 'editor',
            //     meta: {
            //         title: '富文本编辑器',
            //         permiss: '291',
            //     },
            //     component: () => import(/* webpackChunkName: "editor" */ '../views/pages/editor.vue'),
            // },
            // {
            //     path: '/markdown',
            //     name: 'markdown',
            //     meta: {
            //         title: 'markdown编辑器',
            //         permiss: '292',
            //     },
            //     component: () => import(/* webpackChunkName: "markdown" */ '../views/pages/markdown.vue'),
            // },
            // {
            //     path: '/export',
            //     name: 'export',
            //     meta: {
            //         title: '导出Excel',
            //         permiss: '34',
            //     },
            //     component: () => import(/* webpackChunkName: "export" */ '../views/table/export.vue'),
            // },
            // {
            //     path: '/import',
            //     name: 'import',
            //     meta: {
            //         title: '导入Excel',
            //         permiss: '33',
            //     },
            //     component: () => import(/* webpackChunkName: "import" */ '../views/table/import.vue'),
            // },
            // {
            //     path: '/theme',
            //     name: 'theme',
            //     meta: {
            //         title: '主题设置',
            //         permiss: '7',
            //     },
            //     component: () => import(/* webpackChunkName: "theme" */ '../views/pages/theme.vue'),
            // },
            // {
            //     path: '/calendar',
            //     name: 'calendar',
            //     meta: {
            //         title: '日历',
            //         permiss: '24',
            //     },
            //     component: () => import(/* webpackChunkName: "calendar" */ '../views/element/calendar.vue'),
            // },
            // {
            //     path: '/watermark',
            //     name: 'watermark',
            //     meta: {
            //         title: '水印',
            //         permiss: '25',
            //     },
            //     component: () => import(/* webpackChunkName: "watermark" */ '../views/element/watermark.vue'),
            // },
            // {
            //     path: '/carousel',
            //     name: 'carousel',
            //     meta: {
            //         title: '走马灯',
            //         permiss: '23',
            //     },
            //     component: () => import(/* webpackChunkName: "carousel" */ '../views/element/carousel.vue'),
            // },
            // {
            //     path: '/tour',
            //     name: 'tour',
            //     meta: {
            //         title: '分步引导',
            //         permiss: '26',
            //     },
            //     component: () => import(/* webpackChunkName: "tour" */ '../views/element/tour.vue'),
            // },
            // {
            //     path: '/steps',
            //     name: 'steps',
            //     meta: {
            //         title: '步骤条',
            //         permiss: '27',
            //     },
            //     component: () => import(/* webpackChunkName: "steps" */ '../views/element/steps.vue'),
            // },
            // {
            //     path: '/form',
            //     name: 'forms',
            //     meta: {
            //         title: '表单',
            //         permiss: '21',
            //     },
            //     component: () => import(/* webpackChunkName: "form" */ '../views/element/form.vue'),
            // },
            // {
            //     path: '/upload',
            //     name: 'upload',
            //     meta: {
            //         title: '上传',
            //         permiss: '22',
            //     },
            //     component: () => import(/* webpackChunkName: "upload" */ '../views/element/upload.vue'),
            // },
            // {
            //     path: '/statistic',
            //     name: 'statistic',
            //     meta: {
            //         title: '统计',
            //         permiss: '28',
            //     },
            //     component: () => import(/* webpackChunkName: "statistic" */ '../views/element/statistic.vue'),
            // },
        ],
    },
   


    {
        path: '/login',
        meta: {
            title: '登录',
            noAuth: true,
        },
        component: () => import(/* webpackChunkName: "login" */ '../views/pages/login.vue'),
    },
    {
        path: '/register',
        meta: {
            title: '注册',
            noAuth: true,
        },
        component: () => import(/* webpackChunkName: "register" */ '../views/pages/register.vue'),
    },
    {
        path: '/reset-pwd',
        meta: {
            title: '重置密码',
            noAuth: true,
        },
        component: () => import(/* webpackChunkName: "reset-pwd" */ '../views/pages/reset-pwd.vue'),
    },
    {
        path: '/403',
        meta: {
            title: '没有权限',
            noAuth: true,
        },
        component: () => import(/* webpackChunkName: "403" */ '../views/pages/403.vue'),
    },
    {
        path: '/404',
        meta: {
            title: '找不到页面',
            noAuth: true,
        },
        component: () => import(/* webpackChunkName: "404" */ '../views/pages/404.vue'),
    },
    { path: '/:path(.*)', redirect: '/404' },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    NProgress.start();
    const role = localStorage.getItem('vuems_name');
    const permiss = usePermissStore();

    if (!role && to.meta.noAuth !== true) {
        next('/login');
    } else if (typeof to.meta.permiss == 'string' && !permiss.key.includes(to.meta.permiss)) {
        // 如果没有权限，则进入403
        next('/403');
    } else {
        next();
    }
});

router.afterEach(() => {
    NProgress.done();
});

export default router;
